package mall.service.impl;

import java.util.List;

import mall.bean.Category;
import mall.dao.BaseDao;
import mall.dao.CategoryDao;
import mall.dao.impl.CategoryDaoImpl;
import mall.service.CategoryService;

public class CategoryServiceImpl extends BaseServiceImpl<Category, Long> implements CategoryService {

	private CategoryDao categoryDao = new CategoryDaoImpl();

	@Override
	public BaseDao<Category, Long> getDao() {
		return this.categoryDao;
	}

	@Override
	public List<Category> findByParent(long parentId)  {
		return this.categoryDao.findListByParent(parentId);
//		List<Category> categories = this.categoryDao.findAll();
//		ArrayList<Category> result = new ArrayList<Category>();
//		for (Category category : categories) {
//			if (category.getParentId() == parentId) {
//				result.add(category);
//			}
//		}
//		return result;
	}

	@Override
	public List<Category> findPageList(int pageNo, int pageSize) {
		int skip = (pageNo-1) * pageSize; // 跳过?行
		int take = pageSize; // 取?行
		return this.categoryDao.findPageList(skip, take);
	}

	@Override
	public List<Category> findAll() {
		return this.categoryDao.findAll();
	}

}
